//
//  OrderStatusView.m
//  PigMarket
//
//  Created by Felix on 2019/3/22.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "OrderStatusView.h"

#import "BadgeView.h"

@interface OrderStatusView ()

/**
 title
 */
@property (nonatomic , strong) UILabel *title;

/**
 detail
 */
@property (nonatomic , strong) UILabel *detail;

/**
 gtImageView
 */
@property (nonatomic , strong) UIImageView *gtImageView;

/**
 line
 */
@property (nonatomic , strong) UILabel *line;

/**
 statusView
 */
@property (nonatomic , strong) UIView *statusView;

/**
 statusData
 */
@property (nonatomic , strong) NSArray *statusData;

@end

@implementation OrderStatusView

#pragma mark - init method
- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.statusData = @[@{@"title" : @"待付款",@"icon" : @"order_waitpay"},
                            @{@"title" : @"待发货",@"icon" : @"order_waitdeliver"},
                            @{@"title" : @"待收货",@"icon" : @"order_waittake"},
                            @{@"title" : @"待评价",@"icon" : @"order_waitevaluate"},
                            @{@"title" : @"退款/售后",@"icon" : @"order_refund"}];
        
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.title];
    [self addSubview:self.detail];
    [self addSubview:self.gtImageView];
    [self addSubview:self.line];
    [self addSubview:self.statusView];
    [self initStatusBtn];
}

- (void)initLayout {
    // 布局子控件
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(12);
    }];
    [self.gtImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.centerY.mas_equalTo(self.title.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    [self.detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.gtImageView.mas_left).offset(4);
        make.centerY.mas_equalTo(self.title.mas_centerY);
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.title.mas_bottom).offset(12);
        make.height.mas_equalTo(1);
    }];
    [self.statusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(self.line.mas_bottom);
    }];
//    CGFloat spacing = (SCREEN_WIDTH - 24 - 36 * 5 - 19 * 4) / 2;
    [self.statusBtnArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
    [self.statusBtnArray mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(85);
        make.bottom.mas_equalTo(0);
    }];
}

- (void)initStatusBtn {
    for (int i = 0; i < 5; i++) {
        NSDictionary *dic = self.statusData[i];
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:dic[@"icon"]]];
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = dic[@"title"];
        titleLabel.font = [UIFont smallFont];
        titleLabel.textColor = [UIColor colorWithHexString:@"#262626"];
        
        BadgeView *badgeView = [[BadgeView alloc] initNumBadgeView];
        badgeView.numLabel.text = @"1";
        HButtonView *btn = [[HButtonView alloc] initWithTopIcon:iconView badgeView:badgeView title:titleLabel];
        if (i == 1) {
            btn.badgeView.hidden = YES;
        } else {
            btn.badgeView.hidden = NO;
        }
        [self.statusView addSubview:btn];
        [self.statusBtnArray addObject:btn];
    }
}

#pragma mark - getter and setter

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = [UIColor colorWithHexString:@"#262626"];
        _title.font = [UIFont middleFont];
        _title.text = @"我的订单";
    }
    return _title;
}
- (UILabel *)detail {
    if (!_detail) {
        _detail = [[UILabel alloc] init];
        _detail.textColor = [UIColor colorWithHexString:@"#999999"];
        _detail.font = [UIFont smallFont];
        _detail.text = @"查看全部订单";
    }
    return _detail;
}
- (UIImageView *)gtImageView {
    if (!_gtImageView) {
        _gtImageView = [[UIImageView alloc] init];
        _gtImageView.image = [UIImage imageNamed:@"user_gt"];
    }
    return _gtImageView;
}
- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = [UIColor dividerColor];
    }
    return _line;
}
- (UIView *)statusView {
    if (!_statusView) {
        _statusView = [[UIView alloc] init];
    }
    return _statusView;
}
- (NSMutableArray<HButtonView *> *)statusBtnArray {
    if (!_statusBtnArray) {
        _statusBtnArray = [NSMutableArray array];
    }
    return _statusBtnArray;
}
- (NSArray *)statusData {
    if (!_statusData) {
        _statusData = [NSArray array];
    }
    return _statusData;
}

@end
